# Contributor: Jakub Jirutka <jakub@jirutka.cz>
# Maintainer: Jakub Jirutka <jakub@jirutka.cz>
pkgname=xar
# NOTE: Gentoo, Fedora and some others use this 1.8.0 prefix,
#  not sure why exactly tbh.
pkgver=1.8.0.498
_pkgver=${pkgver#1.8.0.}
pkgrel=0
pkgdesc="The eXtensible ARchiver for Apple's .pkg"
url="https://github.com/apple-oss-distributions/xar"
arch="all"
license="BSD-3-Clause"
depends_dev="$pkgname=$pkgver-r$pkgrel"
makedepends="
	autoconf
	bzip2-dev
	libxml2-dev
	musl-fts-dev
	openssl-dev
	zlib-dev
	"
subpackages="
	$pkgname-dev
	$pkgname-doc
	libxar
	"
source="https://github.com/apple-oss-distributions/xar/archive/xar-$_pkgver/xar-$pkgver.tar.gz
	0001-ext2.patch
	0002-arm-ppc.patch
	0003-openssl-1.1.patch
	0004-safe_dirname.patch
	0005-linux.patch
	0006-non-darwin.patch
	0007-variable-sized-object.patch
	"
builddir="$srcdir/xar-xar-$_pkgver/xar"
options="!check"  # no tests provided

prepare() {
	default_prepare
	update_config_sub
	update_config_guess

	# Kill RPATH.
	sed -i 's/-Wl,-rpath,//g' configure.ac

	# Show full version number in --version.
	sed -i "s/XAR_VERSION/\"$pkgver\"/" src/xar.c

	# Make lib headers available without installing first.
	mv lib/*.h include/

	# Allow xar/xar.h to be found.
	ln -s . include/xar

	NOCONFIGURE=1 ./autogen.sh
}

build() {
	# -Wno-unused-result - allow to see real problems
	CFLAGS="$CFLAGS -Wno-unused-result" \
	LIBS="$(pkgconf --libs openssl) $(pkgconf --libs musl-fts)" \
	./configure \
		--build=$CBUILD \
		--host=$CHOST \
		--prefix=/usr \
		--sysconfdir=/etc \
		--mandir=/usr/share/man
	make
}

package() {
	make install DESTDIR="$pkgdir"
}

libxar() {
	default_libs
}

sha512sums="
ecd6186e42ff3005296d94ce01d7fbea04814f26afe1df0449ffa522009ec85beafc71e25931b215910c159a2440565e7dd31a6a7c50389a50a1368bd5ff5f75  xar-1.8.0.498.tar.gz
9a32fed4c7c7ce7b5c072802e81b41f2d0cec906ce3937af93c5157125201992b250a6de1e796c514ded21a3825f749510af99bd45ff174f54be65737f9a9e19  0001-ext2.patch
cbb8f1d714872c8614bbaf5a7570901f4409dbb7ea40cdd44f3b8e62149fb4890030ed0c96ee414a95d08b4c0c0b95f87ace58f0cbf46647b8e2c4c4f889a331  0002-arm-ppc.patch
0f5cfe96e54c9750b8676d94c5784cbf1c1a3c336e180e12d182460abe1b48c806a97b09562ff4430adc5148e1eb53b75ca6c4cf7121049b3e4f1f4b0007094b  0003-openssl-1.1.patch
f1581948b958fdfbfec86e90b3bb629df35a6853cfe8ca5db91a6b4776c675363a56e5462e80bdb217ed93a429b3cf66c068da1ee9bd55634df7d9c60140a285  0004-safe_dirname.patch
1b16ffff2cc72ec508e3aa3ae6c3ebf49ab934013a020e9e7e83026f9763c55d30326ebb1aeed054b41aaf6e92b96e16bd33500b156c7fa94a238f47fd749c6e  0005-linux.patch
ca7e6cfea7405c5001176f8f162c668c6cfbde72a9fa70bae9d8ddc8db393d6833215aa160d53f9ebdbbd73c2030120eb88ff05397e24c7dbbfaa78d26010c01  0006-non-darwin.patch
ee5c730d5d8762823ad1bb01febcbf07be1afd81d4c21e76fbd68f28ddfd1d2006275198c751309804c1ca17933497a735e9c4f870679123731f0c8f8b247318  0007-variable-sized-object.patch
"
